package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldContract;
import com.cleaningcloud.cld.domain.CldProject;
import com.cleaningcloud.cld.domain.dto.ClockInDto;
import com.cleaningcloud.cld.domain.vo.CldProjectContractVo;
import com.cleaningcloud.cld.domain.vo.CldProjectVo;
import com.cleaningcloud.cld.service.ICldProjectService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目Controller
 *
 * @author cleaningcloud
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/project")
public class CldProjectController extends BaseController {
    @Autowired
    private ICldProjectService cldProjectService;

    /**
     * 查询项目列表
     */
    @RequiresPermissions("cld:project:list")
    @GetMapping("/list")
    public TableDataInfo list(CldProject cldProject) {
        startPage();
        List<CldProjectVo> list = cldProjectService.selectCldProjectList(cldProject);
        return getDataTable(list);
    }


    /**
     * 查询项目签订列表
     */
    @RequiresPermissions("cld:project:list")
    @GetMapping("/signList")
    public TableDataInfo signList(CldProject cldProject) {
        startPage();
        List<CldProjectContractVo> list = cldProjectService.selectCldProjectContractList(cldProject);
        return getDataTable(list);
    }

    /**
     * 获取项目详细信息
     */
    @RequiresPermissions("cld:project:query")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId) {
        return success(cldProjectService.selectCldProjectByProjectId(projectId));
    }

    /**
     * 获取项目列表
     */
    @GetMapping("/getList")
    public AjaxResult getList(CldProject cldProject) {
        return success(cldProjectService.getList(cldProject));
    }

    /**
     * 修改打卡地点
     */
    @RequiresPermissions("cld:project:edit")
    @Log(title = "修改打卡地点", businessType = BusinessType.UPDATE)
    @PutMapping("clockIn")
    public AjaxResult clockIn(@RequestBody ClockInDto clockInDto) {
        return toAjax(cldProjectService.clockIn(clockInDto));
    }

    /**
     * 新增项目
     */
    @RequiresPermissions("cld:project:add")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldProject cldProject) {
        return toAjax(cldProjectService.insertCldProject(cldProject));
    }

    /**
     * 修改项目
     */
    @RequiresPermissions("cld:project:edit")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldProject cldProject) {
        return toAjax(cldProjectService.updateCldProject(cldProject));
    }

    /**
     * 删除项目
     */
    @RequiresPermissions("cld:project:remove")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds) {
        return toAjax(cldProjectService.deleteCldProjectByProjectIds(projectIds));
    }


    /**
     * 项目终止
     */
    @RequiresPermissions("cld:project:termination")
    @Log(title = "项目终止", businessType = BusinessType.UPDATE)
    @PutMapping("projectTermination")
    public AjaxResult projectTermination(@RequestBody CldContract cldContract) {
        return toAjax(cldProjectService.termination(cldContract));
    }

    /**
     * 续签项目
     */
    @RequiresPermissions("cld:project:renewal")
    @Log(title = "项目续签", businessType = BusinessType.UPDATE)
    @PutMapping("projectRenewal/{projectId}")
    public AjaxResult projectRenewal(@PathVariable Long projectId) {
        return toAjax(cldProjectService.projectRenewal(projectId));
    }


}
